package com.ruyuan.little.project.rocketmq.api.login.controller;

import com.alibaba.fastjson.JSON;
import com.ruyuan.little.project.common.dto.CommonResponse;
import com.ruyuan.little.project.rocketmq.api.login.dto.LoginRequestDTO;
import com.ruyuan.little.project.rocketmq.api.login.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/api/login")
public class LoginController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);

    @Resource
    private LoginService loginService;
    /**
     * @Author dakun
     * @Description //登陆请求
     * @Date 12:56 2021/6/27
     * @Param [loginRequestDTO] 登陆信息
     * @return CommonResponse
     **/
    @PostMapping(value ="/wxLogin")
    public CommonResponse wxLogin(@RequestBody LoginRequestDTO loginRequestDTO){
        //TODO 模拟接受到用户登录请求
        LOGGER.info("login success user info:{}", JSON.toJSONString(loginRequestDTO));

        loginService.firstLoginDistributeCoupon(loginRequestDTO);

        return CommonResponse.success();
    }

    /**
     * @Author dakun
     * @Description //重置登录状态
     * @Date 12:55 2021/6/27
     * @Param [phoneNUmber]
     * @return CommonResponse
     **/
    @GetMapping(value = "/resetLoginStatus")
    public CommonResponse resetFirstLoginStatus(@RequestParam(value = "phoneNumber") String phoneNUmber){
        LOGGER.info("reset user first login status phoneNumber:{}",phoneNUmber);
        loginService.resetFirstLoginStatus(phoneNUmber);
        return CommonResponse.success();
    }



}
